export default {
    namespaced: true,
    state: {
        list: [
            { id: 100, name: "吃饭", isDone: true },
            { id: 101, name: "睡觉", isDone: false },
            { id: 102, name: "打豆豆", isDone: true },
        ],
        isSel:'all'
    },
    getters: {
        countList(state) {
            return state.list.length
        },
        // 计算任务变化
        isSelFn(state) {
            if (state.isSel === 'no') {
             return   state.list.filter(item => !item.isDone)
            }else if (state.isSel === 'yes') {
                return  state.list.filter(item => item.isDone)
            } else {
                return  state.list
            }
        },
    },
    mutations: {
        // 添加任务
        addlist(state, val) {
            state.list.push({
                id: state.list.length !== 0 ? state.list[state.list.length - 1].id + 1 : 100,
                name: val,
                isDone:false
            })
        },
        // 删除任务
        delList(state, id) {
            state.list = state.list.filter(item => item.id !== id)
        },
        // 切换任务
        isSelTask(state, val) {
            state.isSel = val
        },
        // 清除已完成
        removeList(state) {
           state.list = state.list.filter(item => item.isDone !== true) 
        },
        // 全选影响小选
        selectAll(state, val) {
            state.list.forEach(item => item.isDone = val)
        }
    }
}